#include "InitializationTests.h"
#include "stdafx.h"
#include "TestUtils.h"
//#include "Graph.h"
#include "VertexDirectory.h"
#include <cstdlib>
#include <iostream>

using namespace std;

TestUtils::TestResult ValidateGraphState(int n, int w, ChainParser &chainFile, Chain* chain, set<vector<bool> >* vertices) 
{
	int counter = 0; // will count how many vertices are in all the groups.
	
	int numGroups = chainFile.GetNumberOfGroups();
	//list<Group*>::iterator
	for(int i = 1; i <= numGroups; i++)
	{
			int groupName = i;
			Group* group = chain->GetGroup(groupName);
			vector<bool> *vertexName = chainFile.GetFirstVertex(i);

			//go through the group vertices and make sure they point to the right container
			while (vertexName != NULL)
			{
				Vertex* vertex = VertexDirectory::GetStaticCopyVertex(*vertexName);
				if (TestUtils::VerifyIsTrue(vertex->IsInGraph() == false ,"Vertex was not moved to a group") == TestUtils::TestFailed)
				{
					return TestUtils::TestFailed;
				}
				if (TestUtils::VerifyIsTrue(vertex->GetContainer() == group ,"Vertex was not moved to a group") == TestUtils::TestFailed)
				{
					return TestUtils::TestFailed;
				}
				counter++;
				//cout << vertexNameStr << "		" <<group->GetGroupName() << endl;
				
				delete vertexName;
				vertexName = chainFile.GetNextVertex();
			}
		}
	
	//check that all the vertices that are not in groups are really in graphs
	int verticesInGraph = vertices->size() - counter;
	set<vector<bool> >::iterator verticesIt;
	for (verticesIt = vertices->begin(); verticesIt != vertices->end(); verticesIt++)
	{
		Vertex* vertex = VertexDirectory::GetStaticCopyVertex(*verticesIt);
		if (vertex->IsInGraph() == true)
		{
			verticesInGraph--;
		}
	}
	if (TestUtils::VerifyIsTrue(verticesInGraph == 0 ,"vertices in graph don't appear as vertices in the graph") == TestUtils::TestFailed)
	{
		return TestUtils::TestFailed;
	}

	return TestUtils::TestPassed;
}